package net.lzzy.practices;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author AndyStern
 */
@Component
public class PracticesMvConfigurer implements WebMvcConfigurer {
    @Value("${user.pic}")
    private String picPath;
    @Value("${pic.size}")
    private int maxPicSize;

    @Bean
    public CommonsMultipartResolver multipartResolver(){
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setMaxUploadSize(maxPicSize);
        return resolver;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("file:/"+picPath,
                        "classpath:/webapp/",
                        "classpath:/static/",
                        "classpath:/public/");
        //通过配置URL规则和要查找的位置，Spring MVC在处理静态资源请求时，按照指定的路径规则从这些位置查找相应的资源文件，
        // 从而能够提供正确的静态资源访问服务 (如图片、脚本、页面的样式表等等)
    }


}
